
function LoadRefundItem()
{
	if($("#foreventbutton").val() == ""){
		var descriptionId = "description";
	}else{
		var descriptionId = "descriptionSingle";
	}
	var chargeIdArray = new Array();
	var resIdArray = new Array();
	var text = "";
	var z = new Array();
	var totalSum = 0;
	for(var i= 0;i<$("input[name*=checkbox_charge_res]:visible:checked").size();i++){
		z[i] = $($("input[name*=checkbox_charge_res]:visible:checked")[i]).attr("name").split("").pop();
	}
	for(var i= 0;i<$("input[name*=checkbox_charge_res]:visible:checked").size();i++){
		totalSum += parseFloat($("#charge"+z[i]).attr("charge"))+parseFloat($("#tax"+z[i]).attr("tax"));
		if(i%2 == 0){
			 text +="<tr style=\"background-color:#B5B7F9;\" id=\"refundlist"+i+"\" name=\"refunditem\">"+
			"<td colspan=\"1\" width=\"50%\" >"+
			"<span style=\"padding-left:10px;\">"+(i+1)+".&nbsp;</span><span id=\"payment-refund-item"+i+"\">"+$("#"+descriptionId +z[i]).html()+"</span>"+
			"</td>"+
			"<td colspan=\"1\" width=\"50%\">"+
			"<div style=\"float:right;padding-right:15px;\"><span id=\"payment-refund-item-price"+i+"\">"+toCurrencyString((parseFloat($("#charge"+z[i]).attr("charge"))+parseFloat($("#tax"+z[i]).attr("tax"))),false)+"</span></div>"+
			"</td>"+
			"</tr>";
		}else{
			 text +="<tr style=\"background-color:#FFFFFF;\" id=\"refundlist"+i+"\" name=\"refunditem\">"+
			"<td colspan=\"1\" width=\"50%\" >"+
			"<span style=\"padding-left:10px;\">"+(i+1)+".&nbsp;</span><span id=\"payment-refund-item"+i+"\">"+$("#description"+z[i]).html()+"</span>"+
			"</td>"+
			"<td colspan=\"1\" width=\"50%\">"+
			"<div style=\"float:right;padding-right:15px;\"><span id=\"payment-refund-item-price"+i+"\">"+toCurrencyString((parseFloat($("#charge"+z[i]).attr("charge"))+parseFloat($("#tax"+z[i]).attr("tax"))),false)+"</span></div>"+
			"</td>"+
			"</tr>";
		}
	}
$("[id*=refundlist]").not($("[id*=refundlist]:first")).remove();
$("[id*=payment-refund-item-totle]").html(toCurrencyString(totalSum,false));
$("[id*=refundlist]").replaceWith(text);
}

function AddRefund(){
	var resId_single = $("#foreventbutton").val();
	var chargeIdArray = new Array();
	var obj={};
	obj.AttrchargeIdArray = new Array();
	for(var i= 0;i<$("input[name*=checkbox_charge_res]:visible:checked").size();i++){
		chargeIdArray[i] = $($("input[name*=checkbox_charge_res]:visible:checked")[i]).attr("value");
	obj.AttrchargeIdArray[i] = $($("input[name*=checkbox_charge_res]:visible:checked")[i]);
	}
	var link = "/chargeService?func=editRefund&chargeIdArray="+chargeIdArray;
	simpleserviceWithArgs(link,null,AddRefundSuccess,obj);
}

function AddRefundSuccess(data,obj)
{
	var objArray = new Array();
	objArray = JSON.parse(data);
	var checkLogOut = CheckSession(objArray);
	if(checkLogOut)
		return;
	if(objArray  == null){
		simpleDialog(saveFail_label,100,null);
	}
	else
	{
		var Tabs = getCurrentTabData();
		for(var i=0;i<obj.AttrchargeIdArray.length;i++)
		{
			$(obj.AttrchargeIdArray[i]).prop('checked', false);
			$(obj.AttrchargeIdArray[i]).attr("disabled", true);
			var textRefund =$(obj.AttrchargeIdArray[i]).parents("tr").clone();
				textRefund.find("[name=roomcharge_refund]").text(refundCharge+"/");
				textRefund.children(":first").find("span:first input").removeAttr("name");
			$(obj.AttrchargeIdArray[i]).parents("tr").after(textRefund.attr("class","isrefund"));	
		}
		
		for(var n=0;n<Tabs.ChargeList.length;n++){
			for(var a=0;a<objArray.length;a++){
				if(Tabs.ChargeList[n].id == objArray[a].id)
				{
					Tabs.ChargeList[a] = objArray[a];
				}
			}
		}
	}
}
